#include "Scanner.h"

Scanner::Scanner()
{
}

void Scanner::init(string data_)
{
	data = preprocess(data_);
	next = 0;
}

char Scanner::peek()
{
	return (next < data.size()) ? data[next] : 0;	
}

char Scanner::pop()
{
	char cur = peek();
    if (next < data.size())
	++next;
    return cur;
}

unsigned Scanner::get_pos()
{
	return next;
}

string Scanner::preprocess(string in)
{
    string out = "";
	string::const_iterator c = in.begin(), up = c + 1;

    //c is de huidige char van in up is de volgende 
    for (; up != in.end(); ++c, ++up)
    {
		out.push_back(*c);
		if ((isalnum(*c) || *c == ')' || *c == '*' || *c == '+') &&
			(*up != ')' && *up != '|' && *up != '*' && *up != '+'))
			out.push_back('.');   
    }
    // Laatste char niet vergeten
    if (c != in.end())
		out.push_back(*c);

    return out;
}